<?php
namespace app\admin\controller;

\think\Loader::import('controller/Controller', \think\Config::get('traits_path') , EXT);

use app\admin\Controller;
use think\Db;

class Files extends Controller
{
    use \app\admin\traits\controller\Controller;
    // 方法黑名单
    protected static $blacklist = [];

    protected function filter(&$map)
    {
        if ($this->request->param("name")) {
            $map['name'] = ["like", "%" . $this->request->param("name") . "%"];
        }
    }

    public function add(){
    	if ($this->request->isAjax()) {
    		$post=$this->request->param();
    		$post['time']=time();
    		Db::startTrans();
    		try {
    		    Db::name('files')->insert($post);
    		    // 提交事务
    		    Db::commit();
    		} catch (\Exception $e) {
    		    // 回滚事务
    		    Db::rollback();
    		    return ajax_return_adv_error($e->getMessage());
    		}
    		return ajax_return_adv('添加成功');
    	}else{
    		return $this->view->fetch('edit');
    	}
    }
    public function file_down_load(){
    	$url=Db::name('files')->where('id',$this->request->param('id'))->value('url');
    	return \File::download('./uploads/file/'.$url);
    }
}
